<template>
  <div class="firstpage">
    <h2 class="header">{{title}}</h2>
    <main>
      <Swiper />
    <div class="firstpage-img">
      <li v-for="(item, index) in list" :key="index">{{item.name}}</li>
    </div>
    <div class="firstpage-Must">
      <div class="title">
        <h1>每日必购</h1>
        <p>大家都在买</p>
      </div>
      <div class="img">
        <img src="@/assets/image/1.gif" alt />
        <img src="@/assets/image/2.gif" alt />
        <img src="@/assets/image/3.gif" alt />
      </div>
      <div class="firstpage-list">
        <div class="tab">
          <ul>
            <li
              v-for="(item, index) in tab"
              :key="index"
              :class="ind===index?'active':''"
              @click="Tab(item.sid,index)"
            >{{item.stext}}</li>
          </ul>
        </div>
        <div class="list">
          <dl v-for="(item, index) in content" :key="index">
            <dt><img :src="item.img" alt="" @click="detal(item.pid)"></dt>
            <dd>
              <h3>{{item.pname}}</h3>
              <p class="des">{{item.des}}</p>
              <span class="mode">{{item.mode}}</span>
              <p class="price">￥{{item.price}}</p>
              <div class="addcart" @click="addshopcart(item)">
                <van-icon name="shopping-cart-o" />
              </div>
            </dd>
          </dl>
         
        </div>
      </div>
    </div>
    </main>
    
  </div>
</template>

<script>
import { mapState } from "vuex";
import { GET_TAB_LIST,SET_addshopcar_LIST } from "../store/type/index";
import { TabContent,DetailList } from "@/api/home";

import Swiper from "@/components/swiper";
import Vue from 'vue';
import { Icon } from 'vant';

Vue.use(Icon);

export default {
  name: "firstpage",
  data() {
    return {
      ind: 0,
      list: [
        { id: 1, name: "狂" },
        { id: 2, name: "欢" },
        { id: 3, name: "倒" },
        { id: 4, name: "计" },
        { id: 5, name: "时" },
        { id: 6, name: "超" },
        { id: 7, name: "值" },
        { id: 8, name: "不" },
        { id: 9, name: "停" },
        { id: 10, name: "歇" },
      ],
      content: [],
      title:""
    };
  },
  components: {
    Swiper,
    Icon
  },
  mounted() {
    document.title = this.$route.meta.title;
    this.title=document.title
    console.log(document.title);
    this.$store.dispatch({ type: GET_TAB_LIST });
    this.Tab(111, 0);
  },
  computed: {
    ...mapState({
      tab: (store) => store.home.tab,
    }),
  },
  methods: {
    async Tab(sid, index) {
      this.ind = index;
      const res = await TabContent(sid);
      this.content = res.data.data;
      console.log(this.content);
    },
    detal(pid){
      this.$router.push("/detal/"+pid)
    },
     addshopcart(item){
      this.$store.commit({type:'SET_addshopcar_LIST',payload:item})
    }
  },
 
};
</script>

<style lang="scss">
.firstpage {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .header{
    width: 100%;
      height: .9rem;
     text-align: center;
      line-height: .9rem;
      background: #fff;
      z-index: 9999999;
  }
  main{
    flex: 1;
    overflow: auto;
  }
  .firstpage-img {
    width: 100%;
    height: 2.6rem;
    margin-top: 10px;
    li {
      float: left;
      width: 5%;
      height: 15%;
      padding: 0.4rem;
      margin: 0.13333rem;
      font-size: 0.8rem;
      color: #fff;
      border-radius: 0.16rem;
      background: #ff6d17;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
  .firstpage-Must {
    width: 100%;
    height: 2.6rem;
    margin-top: 10px;
    .title {
      width: 100%;
      height: 0.7rem;
      display: flex;
      p {
        margin-top: 17px;
        margin-left: 10px;
      }
      h1 {
        margin-top: 10px;
        margin-left: 10px;
        font-size: 20px;
      }
    }
    .img {
      img {
        width: 33.3%;
      }
    }
  }
  .firstpage-list {
    width: 100%;
    .tab::-webkit-scrollbar {
      display: none;
    }
    .tab {
      width: 100%;
      height: 0.7rem;
      overflow: auto;
      ul {
        width: 300%;
        height: 100%;
        display: flex;

        li {
          flex: 1;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
    .list{
      width: 100%;
      dl{
        width:100%;
        height: 3rem;
        display: flex;
        margin-top: 10px;
        dt{
          width: 40%;
          height: 100%;
          margin-left: 10px;
          img{
            width: 100%;
            height: 100%;
          }
        }
        dd{
          width: 60%;
          height: 100%;
          padding: 10px;
          position: relative;
          .des{
            font-size: 12px;
            color: #9B9B9B;
            margin-top: 6px;
          }
          .mode{
            margin-top: 10px;
            width: 30px;
            height: 18px;
            display: block;
            background: orange;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 3px;
          }
          .price{
            font-size: 17px;
            color: red;
            font-weight:600;
            margin-top: 50px;
          }
          .addcart{
            width: 30px;
            height: 30px;
            background: red;

            position: absolute;
            bottom: 15px;
            right: 10px;
            color: white;
            font-size: 18px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
          }
        }
      }
    }
  }
  .active {
    color: #ff6d17;
  }
}
</style>